package org.csu.jpetmanage.service.serviceImpl;

import com.alibaba.fastjson2.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.csu.jpetmanage.mapper.AdminMapper;
import org.csu.jpetmanage.model.Admin;
import org.csu.jpetmanage.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.Random;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Override
    public boolean send(Map<String, Object> param, String phone) {
        //首先判断手机号不可以为空

        if (StringUtils.isEmpty(phone)) return false;
        //在阿里云获取id和密钥并且输入
        DefaultProfile profile = DefaultProfile.getProfile("default", "LTAI5tRpEqW1eQvSAWVfR5s9", "YkNP9IFoKR8x3phkGM7Ml2Zbs4PW8p");
        IAcsClient client = new DefaultAcsClient(profile);

        //调用测试接口(这里的模板不可以改变)
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "阿里云短信测试");
        request.putQueryParameter("TemplateCode", "SMS_154950909");
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            return response.getHttpResponse().isSuccess();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }






}